package uk.ac.shef.dcs.oak.jate.test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import dragon.matrix.IntGiantSparseMatrix;
import uk.ac.shef.dcs.oak.jate.JATEException;
import uk.ac.shef.dcs.oak.jate.core.algorithm.CValueAlgorithm;
import uk.ac.shef.dcs.oak.jate.core.algorithm.CValueFeatureWrapper;
import uk.ac.shef.dcs.oak.jate.core.feature.FeatureCorpusTermFrequency;
import uk.ac.shef.dcs.oak.jate.core.feature.FeatureTermNest;
import uk.ac.shef.dcs.oak.jate.core.feature.indexer.GlobalIndexMem;



/**
 * @author YUANYUHU
 *
 */
public class YYH_TestCvalue {
	public static final String output = "D:\\zzz_yyhtest\\output";
	
	public static AlgorithmTester TestCValue(String output) throws JATEException, IOException{
		
		List<String> tempList = new ArrayList<>();
		tempList.add("ADENOID CYSTIC BASAL CELL CARCINOMA");
		tempList.add("CYSTIC BASAL CELL CARCINOMA");
		tempList.add("ULCERATED BASAL CELL CARCINOMA");
		tempList.add("RECURRENT BASAL CELL CARCINOMA");
		tempList.add("CIRCUMSCRIBED BASAL CELL CARCINOMA");
		tempList.add("BASAL CELL CARCINOMA");
		
		GlobalIndexMem termIndex = new GlobalIndexMem();
		
		for(String term: tempList){
			int result = termIndex.indexTermCanonical(term);
			System.out.println(result+" : "+term);
		}
		
		
		FeatureCorpusTermFrequency termCorpusFreq = new FeatureCorpusTermFrequency(termIndex);
		termCorpusFreq.setTotalCorpusTermFreq(1015);
		Map<Integer,Integer> _termFreqMap  = termCorpusFreq.get_termFreqMap();
		_termFreqMap.put(0, 5);
		_termFreqMap.put(1, 11);
		_termFreqMap.put(2, 7);
		_termFreqMap.put(3, 5);
		_termFreqMap.put(4, 3);
		_termFreqMap.put(5, 984);
		termCorpusFreq.set_termFreqMap(_termFreqMap);
//		1 5 ADENOID CYSTIC BASAL CELL CARCINOMA
//	 	2 11 CYSTIC BASAL CELL CARCINOMA
//		3 7 ULCERATED BASAL CELL CARCINOMA
//		4 5 RECURRENT BASAL CELL CARCINOMA
//		5 3 CIRCUMSCRIBED BASAL CELL CARCINOMA
//		6 984 BASAL CELL CARCINOMA
		
		/*newly added for improving frequency count calculation: ends*/
		
		
		//build a feature store required by the tfidf algorithm, using the processors instantiated above
		/*FeatureCorpusTermFrequency termCorpusFreq =
			new FeatureBuilderCorpusTermFrequency(npcounter, wordcounter, lemmatizer).build(termDocIndex);
		FeatureTermNest termNest =
				new FeatureBuilderTermNest().build(termDocIndex);
				*/
		FeatureTermNest termNest = new FeatureTermNest(termIndex);
		Map<Integer, Set<Integer>> _termNestMap = termNest.get_termNested();
		Set<Integer> set0 = new HashSet<>();
		Set<Integer> set1 = new HashSet<>();
		set1.add(0);
		Set<Integer> set2 = new HashSet<>();
		Set<Integer> set3 = new HashSet<>();
		Set<Integer> set4 = new HashSet<>();
		Set<Integer> set5 = new HashSet<>();
		set5.add(0);
		set5.add(1);
		set5.add(2);
		set5.add(3);
		set5.add(4);
		_termNestMap.put(0, set0);
		_termNestMap.put(1, set1);
		_termNestMap.put(2, set2);
		_termNestMap.put(3, set3);
		_termNestMap.put(4, set4);
		_termNestMap.put(5, set5);
		termNest.set_termNested(_termNestMap);
		

		AlgorithmTester tester = new AlgorithmTester();
		tester.registerAlgorithm(new CValueAlgorithm(), new CValueFeatureWrapper(termCorpusFreq,termNest));
		//tester.execute(termDocIndex, path_to_output);
		tester.execute(null, output);
		System.out.println("Ended at: " + new Date());
		return tester;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			YYH_TestCvalue.TestCValue(output);
		} catch (JATEException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
